package com.java.jdbc;

import java.sql.*;
import java.util.Scanner;

public class LoginDemo {

    public static final String URL = "jdbc:mysql://localhost:3306/testdb1?serverTimezone=GMT&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "123456";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入账号");
        String username = scanner.nextLine();
        System.out.println("请输入密码");
        String password = scanner.nextLine();
        try(Connection connection = DriverManager.getConnection(URL,USERNAME,PASSWORD)) {
            Statement statement = connection.createStatement();
            String sql = "select * from t_user where username='"+ username +"' and password = '"+ password +"'";
            System.out.println(sql);
            ResultSet resultSet = statement.executeQuery(sql);
            if(resultSet.next()){
                System.out.println("登录成功！进入主界面....");
            }else{
                System.out.println("账号或密码错误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}